export function randomId(): number {
  return new Date().getTime() + Math.ceil(Math.random() * 1000) * 1000
}

export function label(text: string, index: number, total: number): { textAlign?: string } {
  const textCfg: { textAlign?: string } = {}
  if (index === 0) {
    textCfg.textAlign = 'left'
  }
  if (index === total - 1) {
    textCfg.textAlign = 'right'
  }
  return textCfg
}

export function scale(obj: object): object {
  const key = ['range', 'tickCount', 'max', 'min', 'mask', 'type', 'nice', 'ticks']
  const res = {}
  for (let i = 0; i < key.length; i++) {
    const k = key[i]
    if (obj.hasOwnProperty(k)) {
      res[k] = obj[k]
    }
  }
  return res
}

export function axis(obj: object, F2: any): object {
  const key = ['label', 'line', 'grid']
  const res = {}
  for (let i = 0; i < key.length; i++) {
    const k = key[i]
    if (obj.hasOwnProperty(k)) {
      if (k === 'line' && obj[k] === true) {
        obj[k] = F2.Global._defaultAxis.line
      } else if (k === 'grid' && obj[k] === true) {
        obj[k] = F2.Global._defaultAxis.grid
      }
      res[k] = obj[k]
    }
  }
  return res
}
